#include "proxydialog.h"
#include "ui_proxydialog.h"

ProxyDialog::ProxyDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ProxyDialog)
{
    ui->setupUi(this);
    QObject::connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    QObject::connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
    QObject::connect(ui->proxyCheckBox, SIGNAL(toggled(bool)), this, SLOT(enaleProxy(bool)));
}

ProxyDialog::~ProxyDialog()
{
    delete ui;
}

void ProxyDialog::enaleProxy(bool Checked)
{
    if (Checked == TRUE)
    {
        ui->hostLabel->setEnabled(TRUE);
        ui->hostEdit->setEnabled(TRUE);
        ui->portLabel->setEnabled(TRUE);
        ui->portEdit->setEnabled(TRUE);
        ui->proxyLoginLabel->setEnabled(TRUE);
        ui->proxyLoginEdit->setEnabled(TRUE);
        ui->proxyPasswordLabel->setEnabled(TRUE);
        ui->proxyPasswordEdit->setEnabled(TRUE);
    }
    if (Checked == FALSE)
    {
        ui->hostLabel->setEnabled(FALSE);
        ui->hostEdit->setEnabled(FALSE);
        ui->portLabel->setEnabled(FALSE);
        ui->portEdit->setEnabled(FALSE);
        ui->proxyLoginLabel->setEnabled(FALSE);
        ui->proxyLoginEdit->setEnabled(FALSE);
        ui->proxyPasswordLabel->setEnabled(FALSE);
        ui->proxyPasswordEdit->setEnabled(FALSE);
    }
}

void ProxyDialog::accepted()
{
    emit set(ui->proxyCheckBox->isChecked(), ui->hostEdit->text(), ui->portEdit->text(), ui->proxyLoginEdit->text(), ui->proxyPasswordEdit->text());
}

void ProxyDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
